package com.meshnetics.gb.stack.core;

import com.meshnetics.gb.Parameter;
import com.meshnetics.gb.type.DataType;

/**
 * Parameter with added int code support.
 *
 * @author mmarkov
 */
public class IBParameter extends Parameter {
    /** The type of this IBParameter. */
    protected DataType type;

    /** The code of IBParameter. */
    protected int code;

    /**
     * Constructs an IBParameter with the given name and value. The default value is set to null.
     * It's code is set to Integer.MAX_VALUE.
     *
     * @param name the name for the IBParameter
     * @param val the value of the IBParameter
     * @throws IllegalArgumentException if the given name is null
     */
    public IBParameter(String name, Object val) {
        this(name, Integer.MAX_VALUE, null, val, null);
    }

    /**
     * Constructs an IBParameter with the given name, value and defaultValue.
     * It's code is set to Integer.MAX_VALUE.
     *
     * @param name the name for the IBParameter
     * @param val the value of the IBParameter
     * @param defaultVal the default value of the IBParameter
     * @throws IllegalArgumentException if the given name is null
     */
    public IBParameter(String name, Object val, Object defaultVal) {
        this(name, Integer.MAX_VALUE, null, val, defaultVal);
    }

    /**
     * Constructs an IBParameter with the given name, code and value. The default value is set to null.
     *
     * @param name the name for the IBParameter
     * @param code int code for the IBParameter
     * @param val the value of the IBParameter
     * @throws IllegalArgumentException if the given name is null
     */
    public IBParameter(String name, int code, Object val) {
        this(name, code, null, val, null);
    }

    /**
     * Constructs an IBParameter with the given name, code, value and default value.
     *
     * @param name the name for the IBParameter
     * @param code the code for the IBParameter
     * @param val the value of the IBParameter
     * @param defaultVal the default value of the IBParameter
     * @throws IllegalArgumentException if the given name is null
     */
    public IBParameter(String name, int code, Object val, Object defaultVal) {
        this(name, code, null, val, defaultVal);
    }

    /**
     * Constructs an IBParameter with the given name, type, value and default value.
     *
     * @param name the name for the IBParameter
     * @param type DataType of this IBParameter
     * @param val the value of the IBParameter
     * @param defaultVal the default value of the IBParameter
     * @throws IllegalArgumentException if the given name is null
     */
    public IBParameter(String name, DataType type, Object val, Object defaultVal) {
        this(name, Integer.MAX_VALUE, type, val, defaultVal);
    }

    /**
     * Constructs an IBParameter with the given name, code, type, value and default value.
     *
     * @param name the name for the IBParameter
     * @param code the code for the IBParameter
     * @param type DataType of this IBParameter
     * @param val the value of the IBParameter
     * @param defaultVal the default value of the IBParameter
     * @throws IllegalArgumentException if the given name is null
     */
    public IBParameter(String name, int code, DataType type, Object val, Object defaultVal) {
        super(name, val, defaultVal);
        this.code = code;
        this.type = type;
    }

    /**
     * Retruns the code of this IBParameter.
     *
     * @return the code of this IBParameter
     */
    public int getCode() {
        return code;
    }

    /**
     * Returns the type of this parameter if it's a DataValue instance or null if it's not.
     *
     * @return the type of this parameter if it's a DataValue instance or null if it's not
     */
    public DataType getType() {
        return type;
    }
}
